home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1999 #2 / Amiga Plus CD - 1999 - No. 2.iso / Magazin / LibGuide / Library_Search.rexx < prev    next >
OS/2 REXX Batch file  |  1997-11-05  |  7KB  |  283 lines

  1. /*
  2. **---------------------------------------
  3. ** 
  4. ** Library_Search.rexx V1.2 - 14.11.96
  5. **
  6. ** Search Libraries.guide for keywords
  7. **
  8. ** © 1996 Heiko Schröder         e-mail: age@thepentagon.com
  9. ** You need LIBS: RexxTricks.library
  10. **
  11. ** Inspirations by Tassos Hadjithmomaoglou
  12. ** AMIL_Search.rexx V0.3  © 1995
  13. **
  14. **----------------------------------------
  15. ** $VER: Library_Search.rexx  V1.2 (14-Nov-96)
  16. **----------------------------------------
  17. **
  18. */
  19.  
  20. /*
  21. ** Path for Viewer
  22. **
  23. ** Enter here the full path of an AmigaGuide Viewer of your choice
  24. ** That's the only thing you should change
  25. */
  26.  
  27. Viewer = 'SYS:Utilities/MultiView'
  28.  
  29. /*
  30. ** Please don't change anything after this line
  31. **----------------------------------------------
  32. */
  33.  
  34. OPTIONS RESULTS
  35.  
  36. SIGNAL ON BREAK_C
  37. SIGNAL ON SYNTAX
  38.  
  39. TRUE=1
  40. FALSE=0
  41.  
  42. R="0A"X
  43. say "›32mSearchIn»Libraries.guide« V1.2 - © Heiko Schröder - 14.11.96 -›m"
  44. say "›33mIf you use ·PowerGuide· you dont need this script."
  45. say "Use instead the »Search«-Button...›m"||R
  46. IF ~show('L',"rexxtricks.library") then do
  47.    IF ~addlib('rexxtricks.library',0,-30,0) then do
  48.       say "Sorry, but I need the rexxtricks.library in LIBS: ..."
  49.       say "Copy it from Libs-Drawer in this directory"
  50.       say "to your LIBS: directory."||R
  51.       SAY "Press »Return« to end."
  52.       PARSE PULL Keyword
  53.       exit
  54.       exit
  55.    end
  56. end
  57.  
  58. /*
  59. ** Check for Libraries.guide in current directory 
  60. ** If Libraries.guide is found then open it, else inform the user
  61. */
  62.  
  63. bool1=OPEN(AMIL_file,'Libraries.guide',"R")
  64.  
  65. IF bool1 = FALSE THEN
  66. DO
  67.    SAY '"Libraries.guide" wasn''t found in the current directory.'
  68.    SAY "Press »Return« to end."
  69.    PARSE PULL Keyword
  70.    EXIT
  71. END
  72. AMIL_Path = 'LibGuide:Libraries.guide'
  73.  
  74. /*
  75. ** Check for argument, else ask for one
  76. */
  77.  
  78. PARSE ARG Keyword
  79.  
  80. IF Keyword = '' THEN
  81. DO
  82.    SAY 'Please input word to search for: (without wildcards) '
  83.    PARSE PULL Keyword
  84.    IF Keyword = '' THEN
  85.    DO
  86.       SAY 'Search abandoned !!!'
  87.       EXIT 0
  88.    END
  89. END
  90.  
  91. SAY d2c(11)||'Searching for "'Keyword'"...'
  92.  
  93. /*
  94. ** Initialize variables
  95. */
  96.  
  97. Counter = 0
  98. Node_Line = 0
  99. Keyword_Line = 0
  100. Node_Name = ''
  101. AMIL_Line = ''
  102.  
  103. /*
  104. ** Create the Library_Search.guide
  105. */
  106.  
  107. if exists("c:search") then do
  108.    address command "c:search >T:node search @node Libraries.guide"
  109.    address command "c:search >T:word search "d2c(34)||Keyword||d2c(34)" Libraries.guide"
  110. end
  111. else do
  112.    say "Sorry, but i need program »SEARCH« in the C: drawer!"||R
  113.    SAY "Press »Return« to end."
  114.    PARSE PULL Keyword
  115.    exit
  116. end
  117.  
  118. say "Creating the guide... Wait one second..."
  119.  
  120. open("test","T:word")
  121. a=readln("test")
  122. if eof("test") then call Ende
  123. close("test")
  124. ReadFile("T:node","liste")            /*Read the T:node in Stem-Variable*/
  125. ReadFile("T:word","wordl")            /*Read the T:word in Stem-Variable*/
  126.  
  127. if wordl.0="0" then
  128.    say "The "||Keyword||" was not found in Libraries.guide!"
  129. else do
  130.    bool1=OPEN(Search_file,'T:Libraries_Search.guide',W)
  131.  
  132.    WRITELN(Search_file,'@database Library_Search')
  133.    WRITELN(Search_file,'@node "Main" "Library_Search V1.2  - 14.11.96 - by Heiko Schröder"')
  134.    WRITELN(Search_file,'')
  135.    WRITELN(Search_file,' The word "@{fg fill}'Keyword'@{fg text}" was found in the following lines:')
  136.    WRITELN(Search_file,'')
  137.  
  138.    i=1
  139.    z=1
  140.    do while 1
  141.       ist1  = liste.i
  142.       ist   = Value(Compress(DelStr(ist1,7)))         /*Linenumber of @node*/
  143.       n=i+1
  144.       next1 = liste.n
  145.       next  = Value(Compress(DelStr(next1,7)))        /*Linenumber of next @node*/
  146.       zeile1= wordl.z
  147.       zeile = Value(Compress(DelStr(zeile1,7)))       /*Linenumber of Keyword*/
  148.  
  149.       if next=0 then next=zeile+1                     /*found KeyWord after last @node*/
  150.  
  151.       if ist>zeile then do                            /*found KeyWord before @node*/
  152.          z=z+1                                        /*next KeyWord*/
  153.       end
  154.  
  155.       if zeile>next then do                           /*found KeyWord after next @node*/
  156.          i=i+1                                        /*next @node*/
  157.       end
  158.  
  159.       if ist<=zeile & zeile<=next then do             /*KeyWord between two @node s*/
  160.          AMIL_Line = ist1                             /*read @node*/
  161.          s1 = DELSTR(DELSTR(AMIL_Line,1,7),1,7)
  162.          Node_Name = DELSTR(s1,INDEX((s1),'"'))
  163.          Node_Line = ist
  164.  
  165.          Search_Line = Delstr(zeile1,1,7)             /*read KeyWord*/
  166.          IF (LEFT(Search_Line,1) ~= '@') | (LEFT(Search_Line,2) = '@{') THEN
  167.          DO
  168.             Counter=Counter+1
  169.             Keyword_Line = zeile - Node_Line
  170.             wo=Index(Upper(Search_Line),Upper(KeyWord))
  171.             l=Length(Keyword)
  172.             vor=DelStr(Search_Line,wo)
  173.             nach=DelStr(Search_Line,1,wo+l-1)
  174.             AMIL_Search_Line = '@{"*" link "LibGuide:Libraries.guide/'Node_Name'" 'Keyword_Line'} 'vor||'@{fg shine}'||KeyWord||'@{fg text}'||nach
  175.             WRITELN(Search_File,AMIL_Search_Line||R||COPIES('-',77))
  176.          END
  177.          z=z+1                                /*next KeyWord*/
  178.          if z>wordl.0 then leave              /*end, if no more KeyWord was found*/
  179.       end
  180.    end
  181. end
  182.  
  183. WRITELN(Search_file,"I have found "||Counter||" possibilities.")
  184.  
  185. WRITELN(Search_file,"@endnode")
  186.  
  187.  
  188. /*
  189. ** Close both files
  190. */
  191. bool1=CLOSE(AMIL_file)
  192. bool1=CLOSE(Search_file)
  193.  
  194. /*
  195. ** Check for Viewer or MultiView/AmigaGuide
  196. */
  197.  
  198. bool1 = EXISTS(Viewer)
  199. IF bool1 = FALSE THEN
  200. DO
  201.    SAY Viewer 'wasn''t found.'
  202.    SAY 'Trying MultiView/AmigaGuide...'
  203.    bool1 = EXISTS('SYS:Utilities/MultiView')
  204.    IF bool1 = FALSE THEN
  205.    DO
  206.       bool1 = EXISTS('SYS:Utilities/AmigaGuide')
  207.       IF bool1 = FALSE THEN
  208.       DO
  209.          SAY 'MultiView/AmigaGuide weren''t found in SYS:Utilities !!!'
  210.          EXIT
  211.       END
  212.       ELSE
  213.       DO
  214.          Viewer = 'SYS:Utilities/AmigaGuide'
  215.       END
  216.    END
  217.    ELSE
  218.    DO
  219.       Viewer = 'SYS:Utilities/MultiView'
  220.    END
  221. END
  222.  
  223. /*
  224. ** View the results from the search
  225. */
  226.  
  227. SAY 'Running 'Viewer'...'||R
  228. ADDRESS COMMAND 'Run >NIL: <NIL:' Viewer 'T:Libraries_Search.guide'
  229. SAY "Press »Return« to end."
  230. PARSE PULL Keyword
  231. ADDRESS COMMAND 'Delete T:Libraries_Search.guide QUIET'
  232. ADDRESS COMMAND 'Delete T:node QUIET'
  233. ADDRESS COMMAND 'Delete T:word QUIET'
  234. ADDRESS COMMAND 'Assign LibGuide: REMOVE'
  235.  
  236. EXIT 0
  237.  
  238. /*
  239. ** End of ARexx script
  240. */
  241. Ende:
  242.    say "Sorry, but »"||KeyWord||"« was not found."||R
  243.    close("test")
  244.     ADDRESS COMMAND 'Delete T:node QUIET'
  245.     ADDRESS COMMAND 'Delete T:word QUIET'
  246.    SAY "Press »Return« to end."
  247.    PARSE PULL Keyword
  248.    ADDRESS COMMAND 'Assign LibGuide: REMOVE'
  249.    EXIT
  250.  
  251. /*
  252. ** Handle the Error condition
  253. */
  254.  
  255. SYNTAX:
  256.     bool1=CLOSE(AMIL_file)
  257.     bool1=CLOSE(Search_file)
  258.     ADDRESS COMMAND 'Delete T:Libraries_Search.guide QUIET'
  259.     ADDRESS COMMAND 'Delete T:node QUIET'
  260.     ADDRESS COMMAND 'Delete T:word QUIET'
  261.     SAY R||'Error at line' SIGL ':' ERRORTEXT(RC)
  262.     SAY 'Please report it to the author'||R
  263.    SAY "Press »Return« to end."
  264.    PARSE PULL Keyword
  265.    ADDRESS COMMAND 'Assign LibGuide: REMOVE'
  266.     EXIT
  267.  
  268. /*
  269. ** Handle the Control C command given by the user
  270. */
  271.  
  272. BREAK_C:
  273.     bool1=CLOSE(AMIL_file)
  274.     bool1=CLOSE(Search_file)
  275.     ADDRESS COMMAND 'Delete T:Libraries_Search.guide QUIET'
  276.     ADDRESS COMMAND 'Delete T:node QUIET'
  277.     ADDRESS COMMAND 'Delete T:word QUIET'
  278.     SAY 'Search aborted...'||R
  279.    SAY "Press »Return« to end."
  280.    PARSE PULL Keyword
  281.    ADDRESS COMMAND 'Assign LibGuide: REMOVE'
  282.     EXIT
  283.